﻿Imports TodoMicroSolutionPackV1.dal.dao
Imports TodoMicroSolutionPackV1.dal.dto

Namespace bl.bo
    Public MustInherit Class genericNhiberateBusinessObject(Of ID, C As genericDTO(Of ID))
        Inherits genericBusinessObject

        Protected _daoFactory As NhibernateDAOFactory
        Protected _dao As genericDAO(Of C, ID)
        Protected _dto As genericDTO(Of ID)


        Public Sub New(ByRef daoFactory As NhibernateDAOFactory, ByRef dto As genericDTO(Of ID))
            _daoFactory = daoFactory
            _dao = _daoFactory.getDao(Of C, ID)()
            _dto = dto
        End Sub

        Public Overridable Sub save()
            If isValid() Then
                _dao.SaveOrUpdate(_dto)
            Else
                Throw New BusinessObjectException(getErrors() + Environment.NewLine + "En objeto " + Me.GetType.FullName)
            End If

        End Sub

        Public Property dataTransferObject As genericDTO(Of ID)
            Get
                Return _dto
            End Get
            Set(ByVal value As genericDTO(Of ID))
                _dto = value
            End Set
        End Property
        Public Overrides Function createRules() As System.Collections.Generic.List(Of Rule)
            Dim rules As List(Of Rule) = MyBase.createRules()
            rules.Add(New SimpleRule("dataTransferObject", "No hay un Objeto de datos seteado", Function() Not _dto Is Nothing))
            Return rules
        End Function

    End Class
End Namespace
